package com.youhong.teethcare.plaque.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.youhong.teethcare.R;

/**
 * Created by Administrator on 2018/9/13.
 */
public class PocketChooseDialog extends Dialog {
    Button btn_ok;
    EditText et;
    ImageView iv_close;

    public void setCallback(PlaqueOnClickCallback callback) {
        this.callback = callback;
    }

    PlaqueOnClickCallback callback;
    public PocketChooseDialog(@NonNull Context context) {
        super(context);
        setContentView(R.layout.dialog_pocketchoose);
        getViews();
    }

    public PocketChooseDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        setContentView(R.layout.dialog_pocketchoose);
        getViews();
    }

    private void getViews() {
        iv_close = findViewById(R.id.dialog_iv_close);
        iv_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PocketChooseDialog.this.dismiss();
            }
        });
        et = findViewById(R.id.dialog_et);
        et.setHint("n/a");

        btn_ok = findViewById(R.id.plaqueChoose_btn_ok);
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (callback != null ) {

                    if(et.getText().length() == 0){
                        callback.onCallback("n/a");
                    }else{

                        callback.onCallback(et.getText().toString());
                    }
                }
                PocketChooseDialog.this.dismiss();
            }
        });
    }


    public interface PlaqueOnClickCallback {
        void onCallback(String text);
    }
}
